async function runPromisesInSeries(promises) {
    for (const promise of promises) {
        await promise();
    }
}

// 示例用法
const task1 = () => new Promise((resolve) => {
    setTimeout(() => {
        console.log("Task 1 completed");
        resolve();
    }, 1000);
});

const task2 = () => new Promise((resolve) => {
    setTimeout(() => {
        console.log("Task 2 completed");
        resolve();
    }, 500);
});

const task3 = () => new Promise((resolve) => {
    setTimeout(() => {
        console.log("Task 3 completed");
        resolve();
    }, 300);
});

// 将任务放入数组
const tasks = [task1, task2, task3];

// 执行
(async () => {
    await runPromisesInSeries(tasks);
    console.log("All tasks completed");
})();
